// pages/message/message.js
const app=getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    bxlist:[],
    wdjlCount:0,//未读记录长度
    type:'',
    redorno:true,
    message:[],
    newmessage:""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  changemessage:function(){
    console.log(1)
    var that=this
    that.setData({redorno:false})
    console.log( that.data.redorno)
  },
  qx:function(){
    var that=this
    that.setData({redorno:true})
  },
  newmessage:function(e){
    this.setData({newmessage:e.detail})
  },
  qd:function(){
    var that=this
    wx.request({
      url: app.globalData.URL+'/dormitory_repair/update_call_board',
      method:"POST",
      data:{
        user_id:wx.getStorageSync('userid'),
        password:wx.getStorageSync('password'),
        title:that.data.message.title,
        des:that.data.newmessage
      },
      success:function(res){
        console.log(res)
      }
    })
    that.setData({redorno:true})
  },
  onLoad: function (options) {
    var that=this
    that.setData({type:wx.getStorageSync('type')})
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
   var that=this
    wx.request({
      url: app.globalData.URL+'/dormitory_repair/query_call_board',
      method:"POST",
      data:{
        user_id:wx.getStorageSync('userid'),
        password:wx.getStorageSync('password')
      },
      success:function(res){
        console.log(res)
        that.setData({message:res.data})
        that.setData({messagedes:res.data.des})
      }
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that=this
    var user_id = wx.getStorageSync('userid')
    var password = wx.getStorageSync('password')
    wx.request({
      url: app.globalData.URL+'/dormitory_repair/query_repair',
      method:"POST",
      data:{
        user_id,
        password
      },
      success:function(res){
        that.setData({
          bxlist:res.data.repair_info
        })
        var count=0
        for(let i=0;i<res.data.repair_info.length;i++){
          if(res.data.repair_info[i].checked==0&&res.data.repair_info[i].repair_status==1){
            count=count+1
          }
        }
        that.setData({wdjlCount:count})
        if(that.data.wdjlCount==0){
          wx.removeTabBarBadge({
            index: 1
          })
        }else{
          wx.setTabBarBadge({
            index: 1,
            text: that.data.wdjlCount.toString()
          })
        }
      }
    })
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})